<!DOCTYPE html>
<html lang="zh-cn">

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
  <title>培训机构</title>


  <!-- Expand styles -->
  <link href="../css/app/app.css" rel="stylesheet">
  <link href="../css/fonts/font-awesome.min.css" rel="stylesheet">
  <link href="../css/app/default.css" rel="stylesheet">
  <link href="../css/mui/mui.css" rel="stylesheet">
  <link href="../css/mui/mui.picker.min.css" rel="stylesheet" />

</head>

<body>



  <!-- header -->
  <div>
    <div
      class="widget-default widget-body margin-b-5 padding-b-10 display-flex justify-content-between align-items-center">
      <div class="px-search mui-input-row mui-search" style="width: 88%;">
        <img src="../img/search-icon.png" alt="">
        <input class="mui-input-clear" type="text" name="" id="serach" placeholder="培训机构、地址">

      </div>
      <span class="font-16 gray serach">搜索</span>
    </div>

    <div class="widget-default padding-10 display-flex align-center justify-content-between margin-b-3">
      <div class="display-flex align-items-center justify-content-center width33" id="provinceCode">
        <span class="font-14 gray padding-r-10 elli1 provinceCode">全国</span>
        <span class="fa fa-angle-down gray"></span>
      </div>
      <div class="display-flex align-items-center justify-content-center width33" id="serviceTypeCodes">
        <span class="font-14 gray padding-r-10 elli1 serviceTypeCodes">全部分类</span>
        <span class="fa fa-angle-down gray"></span>
      </div>
      <div class="display-flex align-items-center justify-content-center width33" id="sortType">
        <span class="font-14 gray padding-r-10 elli1 sortType">默认排序</span>
        <span class="fa fa-angle-down gray"></span>
      </div>
    </div>

    <!-- 内容 -->
    <div id="pullrefresh" class="mui-content mui-scroll-wrapper" style="margin-top: 106px;">
      <div class="mui-scroll">
        <div id="contentList">
        </div>
      </div>
    </div>


  </div>


  <script src="../js/dsbridge.js"></script>
  <script src="../js/jquery.js"></script>
  <script src="../js/mui/mui.js"></script>
  <script src="../js/mui/mui.picker.min.js"></script>
  <script src="../js/layer.js"></script>
  <script src="../js/city.data-3.js"></script>
  <script src="../js/app/app-base.js"></script>
  <script src="../js/app/app-url.js"></script>
  <script src="../js/app/app-ajax.js"></script>
  <script>


    //地址选择
    var pickerAddress = new mui.PopPicker();
    var pickerClassification = new mui.PopPicker();
    var pickerSort = new mui.PopPicker();
    var keyWords = ''
    var provinceCode = ''
    var serviceTypeCodes = ''
    var sortType = '1'
    var sortTypeList = [{
      value: '1',
      text: '默认排序'
    }, {
      value: '',
      text: '按照服务数量培训 '
    }]

    var page = 1;
    var limit = 10;
    var index = 0;
    //点赞数据index
    var praiseIndex = -1;
    //分享数据index
    var shareIndex = -1;
    var all_data = new Array();

    $(document).ready(function () {
      cityData3.unshift({
        value: '',
        text: '全国'
      })
      pickerAddress.setData(cityData3);
      pickerSort.setData(sortTypeList);
      getServerData(url_businessdatamng_queryList, { pCode: 'TRAN_TYPE' })
      mui.init({
        pullRefresh: {
          container: '#pullrefresh',
          down: {
            auto: true, // 首次进入自动加载
            callback: pulldownRefresh
          },
          up: {
            contentrefresh: '正在加载...',
            callback: pullupRefresh
          }
        }
      });
    });

    /**
    * 下拉刷新具体业务实现
    */
    function pulldownRefresh() {
      page = 1;
      getData()
    }

    /**
    * 上拉加载具体业务实现
    */
    function pullupRefresh() {
      page++;
      getData()
    }

    function getData() {
      var data = {
        userAccId: getUserId(),
        page: page,
        limit: limit,
        keyWords: $('#serach').val(),
        provinceCode: provinceCode,
        serviceTypeCodes: serviceTypeCodes,
        sortType: sortType
      }
      getServerData(url_getTrainOrganizationList, data);
    }
    function getServerDataSuccess(url, data) {
      switch (url) {
        //详情
        case url_getTrainOrganizationList:
          var list = data.data;
          var html_data = "";
          if (page == 1) {
            index = 0;
            all_data.length = 0;
          }
          if (list.length > 0) {
            for (var i = 0; i < list.length; i++) {
              all_data.push(list[i]);
              var s = ''
              if( list[i].serviceType.length>2){
                list[i].serviceType.length = 2
              }
              list[i].serviceType.map(item => {
                s += '<span class="tuli-content1 font-14 tuli-bg" style="margin-right: 0.5em">' + item.name + '</span>'
              })
              html_data += '<div class="widget-default widget-body display-flex margin-b-3 padding-b-10 goDetail" id="' + index + '">' +
                '<div class="position-img-l">' +
                '<img src="' + (isEmpty(list[i].headPortrait) ? "../img/headimg.png" : showSmallImg(list[i].headPortrait)) + '" alt="">' +
                '<img src="../img/v.png" alt="">' +
                '</div>' +
                '<div class="display-flex flex-column margin-l-10 margin-t-f5">' +
                '<p class="no-margin font-16 font-weight black1 elli1">' + list[i].userName + '</p>' +
                '<div class="padding-t-5 padding-b-5">' +
                s +
                '</div>' +
                '<p class="font-12 gray no-margin line-height-18">已培训： ' + list[i].serviceNum + '场<span class="padding-l-20">培训人数：' + list[i].servicePersonNum + '' +
                '人</span></p>' +
                '<p class="font-12 gray no-margin line-height-18">地址：' + list[i].addressDetail + '</p>' +
                '</div>' +
                '</div>'
              index++;
            }
            ;
          }
          if (page == 1) {
            mui('#pullrefresh').pullRefresh().endPulldownToRefresh();
            if (list.length > 0) {
              mui('#pullrefresh').pullRefresh().refresh(true);
            }
            $("#contentList").html(html_data);
          } else {
            $("#contentList").append(html_data);
            mui('#pullrefresh').pullRefresh().endPullupToRefresh(list.length != limit);
          }
          break;
        case url_businessdatamng_queryList:
          var classificationData = data.data.map(item => {
            return { text: item.name, value: item.code }
          })
          console.log(classificationData)
          classificationData.unshift({
            value: '',
            text: '全部分类'
          })
          pickerClassification.setData(classificationData);
          break;
        case url_oper_action_cancel + '?type=praise':

          //取消点赞
          $(".widget-body[id='" + praiseIndex + "']").find(".praiseImg").attr("src", "../img/zai.png");
          var $praiseNum = $(".widget-body[id='" + praiseIndex + "']").find(".praiseNum");
          var praiseNum = Number($praiseNum.text()) - 1;
          if (praiseNum < 0) {
            praiseNum = 0;
          }
          $praiseNum.text(praiseNum);
          break;
      }
    }

    function getServerDataFailed(url, data) {
      mui('#pullrefresh').pullRefresh().endPulldownToRefresh();
      mui('#pullrefresh').pullRefresh().endPullupToRefresh(true);
    }
    $("#provinceCode").on("tap", function () {
      pickerAddress.show(function (item) {
        provinceCode = item[0].value;
        var address = item[0].text;
        getData()
        $(".provinceCode").html(address);
      });
    })

    $("#serviceTypeCodes").on("tap", function () {
      pickerClassification.show(function (item) {
        serviceTypeCodes = item[0].value;
        var address = item[0].text;
        getData()
        $(".serviceTypeCodes").html(address);
      });
    })

    $("#sortType").on("tap", function () {
      pickerSort.show(function (item) {
        sortType = item[0].value;
        var address = item[0].text;
        getData()
        $(".sortType").html(address);
      });

    })
    $('.serach').click(function () {
      page = 1;
      getData()
    })

    //详情
    mui("#contentList").on('tap', '.goDetail', function () {
      var detailIndex = $(this).attr("id");
      log(all_data[detailIndex])
      localStorage.setItem("trainOrganizationId", all_data[detailIndex].id);
      localStorage.setItem("trainOrganizationUserAccId", all_data[detailIndex].userAccId);
      dsBridge.call("goDetail", "");
    });
  </script>

</body>

</html>